<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.3.9: http://docutils.sourceforge.net/" />
<title>python-xmltv</title>
<link rel="stylesheet" href="default.css" type="text/css" />
</head>
<body>
<div class="document" id="python-xmltv">
<h1 class="title">python-xmltv</h1>
<div class="section" id="introduction">
<h1><a name="introduction">Introduction</a></h1>
<p>python-xmltv is a Python module that provides access to XMLTV data. XMLTV is
an XML format for storing TV listings.</p>
<p>More information on XMLTV can be found at <a class="reference" href="http://membled.com/work/apps/xmltv/">http://membled.com/work/apps/xmltv/</a></p>
</div>
<div class="section" id="requirements">
<h1><a name="requirements">Requirements</a></h1>
<p>python-xmltv requires ElementTree, which can be found at
<a class="reference" href="http://effbot.org/zone/element-index.htm">http://effbot.org/zone/element-index.htm</a></p>
</div>
<div class="section" id="installing">
<h1><a name="installing">Installing</a></h1>
<p>Get python-xmltv from <a class="reference" href="http://www.funktronics.ca/python-xmltv/releases/python-xmltv-1.3.tar.gz">http://www.funktronics.ca/python-xmltv/releases/python-xmltv-1.3.tar.gz</a></p>
<p>After untarring, you can install it with the following command:</p>
<pre class="literal-block">
python setup.py install
</pre>
</div>
<div class="section" id="usage">
<h1><a name="usage">Usage</a></h1>
<p>Usage of the module is generally straight-forward:</p>
<pre class="literal-block">
import xmltv
from pprint import pprint

# If you need to change the locale:
# xmltv.locale = 'Latin-1'

# If you need to change the date format used in the XMLTV file:
# xmltv.date_format = '%Y%m%d%H%M%S %Z'

filename = '/path/to/xmltv/file'

# Print info for XMLTV file (source, etc.)
pprint(xmltv.read_data(open(filename, 'r')))

# Print channels
pprint(xmltv.read_channels(open(filename, 'r')))

# Print programmes
pprint(xmltv.read_programmes(open(filename, 'r')))
</pre>
<p>There are currently three functions for reading that should be used:</p>
<blockquote>
<dl class="docutils">
<dt><strong>read_data</strong> <tt class="docutils literal"><span class="pre">(file_object)</span> <span class="pre">-&gt;</span> <span class="pre">dict</span></tt></dt>
<dd><p class="first">Get the source and other info from an XMLTV file.</p>
<p>Returns a dictionary of &lt;tv&gt; attributes, eg:</p>
<pre class="last literal-block">
{'date': u'20030702230041 -0300',
 'generator-info-name': u'tv_grab_na V3.20030629',
 'generator-info-url': u'http://sourceforge.net/projects/xmltv',
 'source-info-name': u'Zap2It',
 'source-info-url': u'http://www.zap2it.com'}
</pre>
</dd>
<dt><strong>read_channels</strong> <tt class="docutils literal"><span class="pre">(file_object)</span> <span class="pre">-&gt;</span> <span class="pre">list</span></tt></dt>
<dd><p class="first">Get all of the channels.</p>
<p>Returns a list of hashes, each representing a channel, eg:</p>
<pre class="last literal-block">
[{'display-name': [(u'Channel 10 ELTV', u'')],
  'id': u'C10eltv.zap2it.com'},
 {'display-name': [(u'Channel 11 CBHT', u'')],
  'icon': [{'desc': '','src': u'http://tvlistings2.zap2it.com/tms_network_logos/cbc.gif'}],
  'id': u'C11cbht.zap2it.com'}]
</pre>
</dd>
<dt><strong>read_programmes</strong> <tt class="docutils literal"><span class="pre">(file_object)</span> <span class="pre">-&gt;</span> <span class="pre">list</span></tt></dt>
<dd><p class="first">Get all of the programmes.</p>
<p>Returns a list of hashes, each representing a programme, eg:</p>
<pre class="last literal-block">
[{'audio': [{'stereo': [u'stereo']}],
  'category': [(u'Biz', u''), (u'Fin', u'')],
  'channel': u'C23robtv.zap2it.com',
  'start': u'20030702000000 ADT',
  'stop': u'20030702003000 ADT',
  'title': [(u'This Week in Business', u'')]},
 {'audio': [{'stereo': [u'stereo']}],
  'channel': u'C36wuhf.zap2it.com',
  'desc': [(u'In an effort to grow up, George proposes marriage to former girlfriend Susan.',
            u'')],
  'rating': [{'system': u'VCHIP', 'value': u'PG'}],
  'start': u'20030702000000 ADT',
  'stop': u'20030702003000 ADT',
  'sub-title': [(u'The Engagement', u'')],
  'subtitles': [{'type': u'teletext'}],
  'title': [(u'Seinfeld', u'')]}]
</pre>
</dd>
</dl>
</blockquote>
<p>There is also a Writer class. It should always write proper XMLTV data. All
strings, except for dictionary keys, should be in Unicode.</p>
<p>It contains the following methods:</p>
<blockquote>
<dl class="docutils">
<dt><strong>__init__</strong> <tt class="docutils literal"><span class="pre">(fp,</span> <span class="pre">encoding=&quot;iso-8859-1&quot;,</span> <span class="pre">date=None,</span> <span class="pre">source_info_url=None,</span> <span class="pre">source_info_name=None,</span> <span class="pre">generator_info_url=None,</span> <span class="pre">generator_info_name=None)</span></tt> -&gt; <tt class="docutils literal"><span class="pre">Writer</span></tt></dt>
<dd><p class="first">Returns a Writer object.</p>
<p>Arguments:</p>
<blockquote class="last">
<dl class="docutils">
<dt><tt class="docutils literal"><span class="pre">fp</span></tt></dt>
<dd>A File object to write XMLTV data to</dd>
<dt><tt class="docutils literal"><span class="pre">encoding</span></tt></dt>
<dd>The text encoding that will be used. <em>Defaults to
``iso-8859-1``</em></dd>
<dt><tt class="docutils literal"><span class="pre">date</span></tt></dt>
<dd>The date this data was generated. <em>Optional</em></dd>
<dt><tt class="docutils literal"><span class="pre">source_info_url</span></tt></dt>
<dd>A URL for information about the source of the data. <em>Optional</em></dd>
<dt><tt class="docutils literal"><span class="pre">source_info_name</span></tt></dt>
<dd>A human readable description of <tt class="docutils literal"><span class="pre">source_info_url</span></tt>.
<em>Optional</em></dd>
<dt><tt class="docutils literal"><span class="pre">generator_info_url</span></tt></dt>
<dd>A URL for information about the program that is generating the
XMLTV document. <em>Optional</em></dd>
<dt><tt class="docutils literal"><span class="pre">generator_info_name</span></tt></dt>
<dd>A human readable description of <tt class="docutils literal"><span class="pre">generator_info_url</span></tt>.
<em>Optional</em></dd>
</dl>
</blockquote>
</dd>
<dt><strong>write_channel</strong> <tt class="docutils literal"><span class="pre">(channel)</span></tt></dt>
<dd><p class="first">Write a channel dictionary</p>
<p>Here's an example channel dictionary:</p>
<pre class="last literal-block">
{'display-name': [(u'Channel 11 CBHT', u'en')],
 'icon': [{'src': u'http://tvlistings2.zap2it.com/tms_network_logos/cbc.gif'}],
 'id': u'C11cbht.zap2it.com',
 'url': u:'http://www.cbc.com'}
</pre>
</dd>
<dt><strong>write_programme</strong> <tt class="docutils literal"><span class="pre">(programme)</span></tt></dt>
<dd><p class="first">Write a programme dictionary</p>
<p>Here's an example programme dictionary:</p>
<pre class="last literal-block">
{'audio': [{'stereo': u'stereo'}],
 'category': [(u'Comedy', u'')],
 'channel': u'C36wuhf.zap2it.com',
 'country': [(u'USA', u'')],
 'credits': [{'producer': [u'Larry David'], 'actor': [u'Jerry Seinfeld']}],
 'date': [u'1995'],
 'desc': [(u'In an effort to grow up, George proposes marriage to former girlfriend Susan.',
           u'')],
 'episode-num': [(u'7 . 1 . 1/1', u'xmltv_ns')],
 'language': [(u'English', u'')],
 'last-chance': [(u'Hah!', u'')],
 'length': [{'units': u'minutes', 'length': 22}],
 'new': [1],
 'orig-language': [(u'English', u'')],
 'premiere': [(u'Not really. Just testing', u'en')],
 'previously-shown': [{'channel': u'C12whdh.zap2it.com',
                       'start': u'19950921103000 ADT'}],
 'rating': [{'icon': [{'height': u'64',
                       'src': u'http://some.ratings/PGicon.png',
                       'width': u'64'}],
             'system': u'VCHIP',
             'value': u'PG'}],
 'star-rating': [{'icon': [{'height': u'32',
                            'src': u'http://some.star/icon.png',
                            'width': u'32'}],
                  'value': u'4/5'}],
 'start': u'20030702000000 ADT',
 'stop': u'20030702003000 ADT',
 'sub-title': [(u'The Engagement', u'')],
 'subtitles': [{'type': u'teletext', 'language': (u'English', u'')}],
 'title': [(u'Seinfeld', u'')],
 'video': [{'colour': 1, 'aspect': u'4:3', 'present': 1}]}
</pre>
</dd>
<dt><strong>end</strong> <tt class="docutils literal"><span class="pre">()</span></tt></dt>
<dd><p class="first">Write end tag</p>
<p class="last">Call this before closing a file.</p>
</dd>
</dl>
</blockquote>
</div>
<div class="section" id="reporting-bugs">
<h1><a name="reporting-bugs">Reporting Bugs</a></h1>
<p>Please send all bugs, comments, and questions to James Oakley
&lt;<a class="reference" href="mailto:jfunk&#64;funktronics.ca">jfunk&#64;funktronics.ca</a>&gt;</p>
</div>
</div>
</body>
</html>
